
$(document).ready(function() {
	searchData();
	//databack();
});

function workerAdd(){
	if(wkId == "nono"){
		wkId = "";
	}
	 var begTime = $("#begTime").val();
	 var endTime = $("#endTime").val();
	 var signTime = $("#signTime").val();
	 var signoutTime = $("#signoutTime").val();
	 var signTime2 = $("#signTime2").val();
	 var signoutTime2 = $("#signoutTime2").val();
	 if(begTime=="" || endTime=="" ){
		 jalert("有效时间不能为空！");
		return; 
	 }
	 if(signTime==""){
		 jalert("首次签到时间不能为空！");
		return; 
	 }
	 if(signoutTime==""){
		 jalert("首次签退时间不能为空！");
		return; 
	 }
	 if(signTime2 !="" && signoutTime2 == ""){
		 jalert("签到时间签退时间要对应！");
		return; 
	 }
	 if(signTime2 =="" && signoutTime2 !=""){
		 jalert("签到时间签退时间要对应！");
		return; 
	 }
	 if(signTime2 !=""){
		 signoutTime = signoutTime2;
	 }
	 var temp = "?begTime="+begTime+"&endTime="+endTime+"&signTime="+signTime +"&signoutTime="+signoutTime+"&wkId="+wkId+"&jobnos="+jobnos ;
	layui.layer.open({
       type: 2,
       area: ['1000px', '480px'],
       title: "新增工人",
       fixed: false,
       maxmin: false,
       content: ctp + "/attendanceController/attenWorker.shtml"+temp
   });
}

function workerIds(recId){
	if(wkId == "nono"){
		wkId = "";
	}
	if(wkId == ""){
		wkId+=recId;	
	}else{
		wkId+=","+recId;
	}
	searchData();
}

function searchData(curr) {
	if(wkId == ""){
		wkId = "nono";
	}
	setTagAndValue("form1","wkIds",wkId);
	//---开始的页数
	setTagAndValue("form1","curr",curr); 
	//---每页几条数据
	setTagAndValue("form1","SUNNADA_PAGE_SIZE",6); 
	getImagesInfo()
}

function getImagesInfo(){
	$.ajax({
		url: ctp + "/attendanceController/attenWorkerSearch.shtml", 
		data: $('#form1').serialize(),
		type: "POST", 
		cache : false, 
		dataType: "json", 
		error: function(request) {
			closeLoading();
		    alert("表单提交出错，请稍候再试");
		},
		success: function(data) {
		    var dataObj = data.list; 
		    var pageJson = data.params;
		    $("#pNum").text(pageJson.rc);
		    //------数据拼接-------
		    editData(dataObj);
		   //------------   分页开始  -------------
		     getPaging(pageJson,dataObj);
		    //------------  分页结束      -------------
	    }

	});
}

function jobnosData(list){
	for (var i = 0; i < list.length; i++) {
		var l = list[i];
		jobnos += l.JOBNO+",";
	}
	var reg = /,$/gi;
	jobnos = jobnos.replace(reg, "");
}

function editData(list){
	$("#tbodyData").html("");
	for (var i = 0; i < list.length; i++) {
		var l = list[i];
		$str="";
		$str+="<tr><td>"+l.NAME+"</td>";
		$str+="<td>"+l.JOBNO+"</td>";
		$str+="<td>"+l.WORKTYPE+"</td>";
		$str+= "<td>"+(l.GROUPNAME == undefined ? '' : l.GROUPNAME) +"</td>";
		$str+= "<td><a onClick=\"getDel(\'"+l.JOBNO+"\')\" class='smart-table_operation'>移除</a></td></tr>";
		$("#tbodyData").append($str);
	}
	
}

function getDel(id){
	jconfirm("del('"+id+"')","是否要移除所选记录？");
}

function del(id){
	var items =wkId.split(",");
	var recIds = "";
	for (var i = 0; i < items.length; i++) {
		if ( id !=items[i]) {
			recIds += items[i]+",";
		}
	}
	 var reg = /,$/gi;
	 wkId = recIds.replace(reg, "");
	 searchData(0);
}




function databack(){
	var str = "";
	if(dbType =='1'){
		str +="<option selected='selected' value='1'>分钟数 X 1元</option>";
	}else{
		str +="<option  value='1'>分钟数 X 1元</option>";
	}
	if(dbType =='2'){
		str +="<option selected='selected' value='2'>分钟数 X 5元</option>";
	}else{
		str +="<option  value='2'>分钟数 X 5元</option>";
	}
	if(dbType =='3'){
		str +="<option selected='selected' value='3'>分钟数 X 10元</option>";
	}else{
		str +="<option  value='3'>分钟数 X 10元</option>";
	}
	 $("#debitType").append(str);
}


function attendanceAdd(){
	if(wkId == "nono"){
		wkId = "";
	}
	if (!Validator.Validate(document.getElementById("form1"), 1)) {
		return;
	}
	 var signTime2 = $("#signTime2").val();
	 var signoutTime2 = $("#signoutTime2").val();
	 if(signTime2 !="" && signoutTime2 == ""){
		 jalert("签到时间签退时间要对应！");
		return; 
	 }
	 if(signTime2 =="" && signoutTime2 !=""){
		 jalert("签到时间签退时间要对应！");
		return; 
	 }
	setTagAndValue("form1","wkIds",wkId);
	$("#pNumber").val($("#pNum").text());
	 for (var i = 0; i < $("#engineerId option").length; i++) {
		 if(true==$("#engineerId option").get(i).selected){
			$("#engineerName").val($("#engineerId option").get(i).text);
		 }
	 }
	$.ajax({ 
	 	url: ctp + "/attendanceController/attendanceSave.shtml",
	    data: $('#form1').serialize(),
		type : 'POST',
		async:false, 
		success : function(result) {  
			if(result=='1') {  
				jalert9("保存成功！");
				setTimeout(function(){
					location.href = ctp + "/attendanceController/attendance.shtml";
					/*parent.searchData();
					closeAttendance();*/
				},WARN_TIME_OUT);
			}else if(result=='2') {     
				jalert("保存失败，有相同的排班名称！");   
			} else if(result=='0') {     
				jalert("保存失败，请联系管理员！");   
			} 
  		}
	});
	
}

function  exceedTimes(){
	$("#exceedTime").val($("#lateTmie3").val());
}

function  lateTmies2(){
	$("#lateTmie2").val($("#lateTmie1").val());
}

//当前弹窗索引
var attendance_index = parent.layui.layer.getFrameIndex(window.name);

//关闭当前弹窗
function closeAttendance(){
	location.href = ctp + "/attendanceController/attendance.shtml";
	//parent.layui.layer.close(attendance_index);
}